package com.whnk.web.controller.model;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.model.domain.TModelInfo;
import com.whnk.model.service.ITModelInfoService;

/**
 * 模型 信息操作处理
 * 
 * @author whwhnk
 * @date 2021-05-28
 */
@Controller
@RequestMapping("/model/tModelInfo")
public class TModelInfoController extends BaseController
{
    private String prefix = "model/tModelInfo";
	
	@Autowired
	private ITModelInfoService tModelInfoService;
	
	@RequiresPermissions("model:tModelInfo:view")
	@GetMapping()
	public String tModelInfo()
	{
	    return prefix + "/tModelInfo";
	}
	
	/**
	 * 查询模型列表
	 */
	@RequiresPermissions("model:tModelInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TModelInfo tModelInfo)
	{
		startPage();
        List<TModelInfo> list = tModelInfoService.selectTModelInfoList(tModelInfo);
		return getDataTable(list);
	}
	
	/**
	 * 新增模型
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存模型
	 */
	@RequiresPermissions("model:tModelInfo:add")
	@Log(title = "模型", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TModelInfo tModelInfo)
	{		
		return toAjax(tModelInfoService.insertTModelInfo(tModelInfo));
	}

	/**
	 * 修改模型
	 */
	@GetMapping("/edit/{iD}")
	public String edit(@PathVariable("iD") String iD, ModelMap mmap)
	{
		TModelInfo tModelInfo = tModelInfoService.selectTModelInfoById(iD);
		mmap.put("tModelInfo", tModelInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存模型
	 */
	@RequiresPermissions("model:tModelInfo:edit")
	@Log(title = "模型", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TModelInfo tModelInfo)
	{		
		return toAjax(tModelInfoService.updateTModelInfo(tModelInfo));
	}
	
	/**
	 * 删除模型
	 */
	@RequiresPermissions("model:tModelInfo:remove")
	@Log(title = "模型", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tModelInfoService.deleteTModelInfoByIds(ids));
	}
	
}
